<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/22
 * Time: 下午1:08
 */

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller;
use App\Http\Presenter\Presenter;
use App\Http\Repository\Repository;
use App\Http\Service\Service;

class BaseController extends Controller
{

    public $view = [];

    protected $presenter;

    protected $repository;

    protected $service;

    /**
     * @param Presenter $presenter
     * @param Repository $repository
     * @param Service $service
     */
    public function __construct(Presenter $presenter, Repository $repository, Service $service)
    {

        $this->presenter = $presenter;

        $this->repository = $repository;

        $this->service = $service;
    }

    /**
     * AJAX返回
     * @param $code
     * @param string $message
     * @param array $data
     * @return array
     */
    protected function send($code, $message = '', $data = []) {
        return [
            'body' => [
                'status' => $code,
                'msg'    => $message,
                'data'   => $data,
            ]
        ];
    }

    /**
     * @param $_token
     * @return bool
     */
    protected function check($_token)
    {
        return in_array($_token, $this->tokens) ? true : false;
    }
}
